using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace InventorySystem.UI
{
    public class UI_Inventory : MonoBehaviour
    {
        [SerializeField]
        private GameObject _inventorySlotPrefab;

        [SerializeField]
        private Inventory _invnetory;

        [SerializeField]
        private List<UI_InventorySlot> _slots;

        public Inventory Inventory => _invnetory;

        [ContextMenu("Initialize Iventory")]
        private void InitializeInventoryUi() 
        {
            if (_invnetory == null || _inventorySlotPrefab == null) return;

            _slots = new List<UI_InventorySlot>(_invnetory.Size);
            for (var i = 0; i < _invnetory.Size; i++) 
            {
                var uiSlot = Instantiate(_inventorySlotPrefab) as GameObject;
                uiSlot.transform.SetParent(transform,false);
                var uiSlotScript = uiSlot.GetComponent<UI_InventorySlot>();
                uiSlotScript.AssignSlot(i);
                _slots.Add(uiSlotScript);


            }

        }
    }
}